package com.api.gbhg.zengping.web;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.zengping.dao.BaseSwitchDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: ecology_zp
 * @author: Mr.zeng
 * @create: 2020-12-18 10:42
 *
 * 控制流程开关
 **/
public class BaseSwitchAction {
    public static final Logger LOGGER = LoggerFactory.getLogger("gbhg");
    public  final RecordSet rs=new RecordSet();
    public static final String TABLE_NAME ="base_switch";

    /**
     * 修改接口
     * @param map
     * @return
     */
    @POST
    @Path("/modifyswitch")
    @Produces(MediaType.APPLICATION_JSON)
    public String modifySwitch(Map<String,String> map){
        String reqid = map.get("reqid");
        String value = map.get("switchValue");
        LOGGER.info("开关修改参数,reqid:"+reqid+",switchValue:"+value);
        // 修改开关
        new BaseSwitchDao().updateById(rs, TABLE_NAME,value,reqid);
        return JSON.toJSONString(new HashMap<String,Integer>().put("code",200));
    }

    /**
     * 返回开关状态
     * @param map
     * @return
     */
    @POST
    @Path("/showSwitchStatus")
    @Produces(MediaType.APPLICATION_JSON)
    public String showSwitchStatus(Map<String,String> map){
        String reqid=map.get("reqid");
        LOGGER.info("返回开关状态参数，reqid:"+reqid);
        // 查询给前台返回结果
        RecordSet recordSet = new BaseSwitchDao().selectById(rs, TABLE_NAME, reqid);
        Map<String,Object> hashmap=new HashMap<String, Object>();
        while (recordSet.next()){
            String switchName = recordSet.getString("switch_name");
            String switchValue = recordSet.getString("switch_value");
            hashmap.put("switchName",switchName);
            hashmap.put("switchValue",switchValue);
        }
        return JSON.toJSONString(hashmap);
    }
}
